package cs2340.lostmystuff;
/**
 * M5: - Feature slice 1
 * For login verification use admin,admin for now
 * In progress of relating the hash table to the fields.
 * Parth Patel
 * Akshat
 * John
 * Renaid
 * Alex
 */



import android.annotation.TargetApi;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.view.Menu;
import android.app.AlertDialog;
import android.content.DialogInterface;


import java.util.HashMap;







@TargetApi(11)

public class MainActivity extends Activity {

	private EditText loginname;
	private EditText loginpass;
	private int counter;
	private boolean lock;
	public String user;
	public String pass;
	AlertDialog dialog;
	

	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final UserTable u = new UserTable();
        
        loginname = (EditText) findViewById(R.id.uname);
        loginpass = (EditText) findViewById(R.id.pword);
        dialog = new AlertDialog.Builder(this).create();
        dialog.setTitle("MSG");
        
        
        Button login = (Button) findViewById(R.id.lbutton);
        Button register = (Button) findViewById(R.id.rbutton);
        if (login.isActivated()){
        	counter += 1;
        }
        
        
       
        login.setOnClickListener(new View.OnClickListener() {
        	
        	public void onClick(View v) {
        		
        		user = loginname.getText().toString();
        		pass = loginpass.getText().toString();
        		
        		
        		
        		if(UserTable.rus.containsKey(user) && UserTable.rus.containsValue(pass)) {
        			Intent mIntent = new Intent(MainActivity.this, HomePageActivity.class);
        			startActivity(mIntent);
        			
        		} else if((UserTable.rus.containsKey(user) == false && UserTable.rus.containsValue(pass) == false)){
        			dialog.setMessage("Either of the fields are wrong. If not a user, click Register");
        			dialog.show();
        			
        		} if ((counter++) == 4){
        			lock = Boolean.valueOf(user);
   					lock = Boolean.valueOf(pass);
   					dialog.setMessage("Your Account has been locked");
   					dialog.show();
        		}
        		
        
        	}
       		
        });
        register.setOnClickListener(new View.OnClickListener() {
        	public void onClick(View v) {
        			Intent myIntent = new Intent(MainActivity.this, RegisterPage.class);
        			startActivity(myIntent);
        			
        		}
        	
        });
    }
	
			
}
	


	
	

  
